package tuio;

import tuio.libTUIO.src.TUIO.TuioCursor;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class TuioTreatment {

	public static boolean isSingleClick(TuioCursor tcur){	
		if(tcur.getTuioTime().subtract(tcur.getStartTime()).getTotalMilliseconds()<300){
			return true;
		}
		return false;
	}



	public static boolean isDoubleTouch(TuioCursor previousCursor, TuioCursor tcur){
		boolean doubleTouch = false;
		if(previousCursor!=null && previousCursor.getCursorID()==tcur.getCursorID()){
			//si dans la meme seconde
			if(previousCursor.getTuioTime().getSeconds()==tcur.getTuioTime().getSeconds()){
				if(tcur.getTuioTime().getMicroseconds()-previousCursor.getTuioTime().getMicroseconds()<300000){
					doubleTouch=true;
				}
			}
			//si second touch dans la seconde suivante
			else if(previousCursor.getTuioTime().getSeconds()==tcur.getTuioTime().getSeconds()-1){
				if(tcur.getTuioTime().getMicroseconds()+999999-previousCursor.getTuioTime().getMicroseconds()<300000){
					doubleTouch=true;
				}
			}
		}
		return doubleTouch;
	}


	public static TCurAndPoint[] order2Touch(TCurAndPoint t1, TCurAndPoint t2){
		TCurAndPoint[] tab = new TCurAndPoint[2];
		double xMin = Math.min(t1.getLocalPoint().getX(), t2.getLocalPoint().getX());
		if(xMin==t1.getLocalPoint().getX()){
			tab[0]=t1;
			tab[1]=t2;
		}
		else{
			tab[0]=t2;
			tab[1]=t1;
		}
		return tab;
	}
}
